package uoit.csci2020u.tutorial3;

import java.io.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Vector;

//import java.util.*;

public class MakeNumber {
	public List<Float> makeRandomNumbers(int count, float max) {
		List<Float> list = new Vector<Float>();
		Random rand = new Random();
		
		for (int i = 0; i < count; i++) {
			list.add(rand.nextFloat() * max);
		}
		
		return list;
	}
	
	public LinkedList<Float> makeLinkedList(List<Float> numbers) {
		LinkedList<Float> list = new LinkedList<Float>();
		list.addAll(numbers);
		
		//LinkedList<Float> list = new LinkedList<Float>(numbers);
		
		return list;
	}
	
	public ArrayList<Float> makeArrayList(List<Float> numbers) {
		ArrayList<Float> list = new ArrayList<Float>();
		list.addAll(numbers);
		
		return list;
	}
	
	public Vector<Float> makeVector(List<Float> numbers) {
		Vector<Float> list = new Vector<Float>();
		list.addAll(numbers);
		
		return list;
	}
	
	public long sortList(List<Float> numbers) {
		long start = System.currentTimeMillis();
		Collections.sort(numbers);
		return System.currentTimeMillis() - start;
	}
	
	public void save(List<Float> numbers, String filename) throws IOException {
		FileOutputStream file = new FileOutputStream(filename);
		DataOutputStream data = new DataOutputStream(file);
		
		for (Float num : numbers) {
			data.writeFloat(num);
		}
		
		data.close();
		file.close();
	}
	
	public List<Float> load(String filename) throws IOException {
		List<Float> list = new ArrayList<Float>();
		FileInputStream file = new FileInputStream(filename);
		DataInputStream data = new DataInputStream(file);
		
		while (true) {
			try {
				list.add(data.readFloat());
			} catch (EOFException ex) {
				return list;
			}
		}
	}
}
